package myLearnjdk.jdk.io.ftp;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;


public class FtpUtil {
 
	public static void main(String[] args) {
		
		URL url = null;
		byte[] car = null;
		BufferedInputStream in = null;
		try {
			byte[] temp = new byte[1024*1024*4];
			int pos = 0;
			car =new  byte[1024];
			url = new URL("ftp://easftp:IJIrKz5e@118.178.225.27/trma/2018-08-17/null/59131e60-1ead-45a4-866d-3bbb05dce7a5.sp4");
			url.openConnection();
			in = new BufferedInputStream(url.openStream());
			System.out.println(in.available());
			
			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File("E://c.log")));
			
			int len =0;
			while((len=in.read(car))!= -1){
				for (int i=0 ; i<len ; i++ ) {
					temp[pos] =car[i] ;
					pos++;
				}
			}
			
			byte[] b  = new byte[pos];
			
			for(int j = 0 ; j< (pos) ; j++){
				b[j] = temp[j];
			}
			out.write(b);
			
		} catch (Exception e) {
			e.printStackTrace();
//			LogUtil.errorInfo(e.getMessage());
		}finally{
			try {
				if(in!=null){
					in.close();
				}
			} catch (IOException e) {
				in = null;
				e.printStackTrace();
			}
		}
	}
}